<?php
    $host = "10.9.98.136";
    $port = "3306";
    $dbname = "seven";
    $user = "dba_user";
    $passwd = "dba_user_!@#";

    $dbh = new PDO("mysql:host=$host;port=$port;dbname=$dbname",$user,$passwd);
    $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    $dbh->exec('set names utf8');

    $sql = "SELECT id,name,sex FROM user";
    $stmt = $dbh->prepare($sql);
    $stmt->execute();

    $userResult = [];
    while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
    $item['ID'] = $row['id'];
    $item['NAMA'] = $row['name'];
    $item['SEX'] = $row['sex'];
    $userResult[] = $item;
    }
    // var_export($userResult);

    $skillSql = "SELECT id,userid,skill FROM skill";
    $stmt = $dbh->prepare($skillSql);
    $stmt->execute();

    $skillResult = [];
    while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
        $item['ID'] = $row['id'];
        $item['SKILL'] = $row['skill'];
        $item['USERID'] = $row['userid'];
        $skillResult[] = $item;
    }
    // var_export($skillResult);
    $result = [];
    foreach($userResult as $k=>$v){
    $key = $v['NAMA'];
    if (!$result[$key]) {
        $result[$key] = [0,0];
    }
    foreach($skillResult as $k1=>$v1){
        if ($v['ID'] == $v1['USERID']){
                $result[$key] = $v1['SKILL'];
        }
    }
    }

    var_export($result);

    
